﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class UIUtility : MonoBehaviour {

	public static GameObject FindChild( GameObject parent , string path ) {
		return parent.transform.FindChild (path).gameObject;
	}

	public static void Hide( GameObject obj  ) {
		obj.GetComponent<CanvasGroup> ().alpha = 0;
		obj.GetComponent<CanvasGroup> ().blocksRaycasts = false;
		obj.GetComponent<CanvasGroup> ().interactable = false;
	}

	public static void Show( GameObject obj ) {
		obj.GetComponent<CanvasGroup> ().alpha = 1;
		obj.GetComponent<CanvasGroup> ().blocksRaycasts = true;
		obj.GetComponent<CanvasGroup> ().interactable = true;
	}
		
	public static void Alpha( GameObject obj , float value ) {
		obj.GetComponent<CanvasGroup> ().alpha = value;
	}

	public static void SetAnchoredPosition( GameObject obj , float x , float y ) {
		obj.GetComponent<RectTransform> ().anchoredPosition = new Vector2 (x, y);
	}

	public static void SetAnchoredPositionX( GameObject obj , float x ) {
		RectTransform rt = obj.GetComponent<RectTransform> ();
		rt.anchoredPosition = new Vector2 ( x , rt.anchoredPosition.y );
	}

	public static void SetAnchoredPositionY( GameObject obj , float y ) {
		RectTransform rt = obj.GetComponent<RectTransform> ();
		rt.anchoredPosition = new Vector2 ( rt.anchoredPosition.x , y );
	}
	 
	public static void SetLocalScale ( GameObject obj , float x , float y ) {
		obj.GetComponent<RectTransform> ().localScale = new Vector3 (x, y, 0);
	}

}
